home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0997.zip / sss_vb.txt < prev    next >
Text File  |  1997-07-22  |  4KB  |  168 lines

  1. _Server-Side Scripting in Visual Basic_
  2. by Al Williams
  3.  
  4. Example 1:
  5.  
  6. (a)
  7.  
  8. Copyright 1997 by Al Williams
  9.  
  10.  
  11. (b)
  12.  
  13. <HTML>
  14. <HEAD>
  15. <TITLE>A Demo Page</TITLE>
  16. </HEAD>
  17. <BODY>
  18. Welcome to this meaningless page.
  19. <!--#include file="copy.inc"-->
  20. </BODY>
  21. <HTML>
  22.  
  23.  
  24. Example 2:
  25.  
  26. (a)
  27.  
  28. The first few Fibonacci numbers:<P>
  29. <% n1=0 n2=1 
  30.       for i= 1 to 100 %>
  31.         Number <%=I %>: <%= n1+n2 %><P>
  32.          <% old=n1
  33.               n1=n2
  34.               n2=old+n2 
  35.        next %>
  36.  
  37. (b)
  38. <% If flag=True %>
  39.    You are authorized to proceed_
  40. <% else %>
  41.    <B>Unauthorized Access Attempted!</B>
  42. <% end if %>
  43.  
  44.  
  45. Listing One
  46. <!--#include file="adovbs.inc" -->
  47. <HTML>
  48. <HEAD>
  49. <TITLE>Report Your Sightings!</TITLE>
  50. </HEAD>
  51. <BODY>
  52. <!-- decide if data is present
  53.      If data is present, process
  54.      Otherwise, show form -->
  55. <% if Request("Content_Length")=0 then %>
  56. <H1>Report your King Sightings Here!<BR>
  57. </H1>
  58. <FORM NAME="KingForm" ACTION="ddjrpt.asp" METHOD="POST">
  59. <PRE WIDTH=132>
  60. <FONT SIZE=2>Date:     </FONT>
  61. <INPUT NAME="KDate" VALUE="" MAXLENGTH="8" SIZE=8>
  62. <FONT SIZE=2 FACE="Courier New">
  63. I've seen the King before: </FONT>
  64. <INPUT TYPE="CHECKBOX" NAME="Before">
  65.  
  66. <FONT SIZE=2 FACE="Courier New">Location: </FONT>
  67. <INPUT NAME="Loc" VALUE="" MAXLENGTH="128" SIZE=64>
  68. <FONT SIZE=2 FACE="Courier New">
  69.  
  70. <FONT SIZE=2 FACE="Courier New">Your name: </FONT>
  71. <INPUT NAME="Name" VALUE="" MAXLENGTH="128" SIZE=64>
  72. <FONT SIZE=2 FACE="Courier New">
  73.  
  74. Comments:
  75. </FONT>
  76. <TEXTAREA NAME="Comment" ROWS=3 COLS=80>
  77. </TEXTAREA>
  78. </PRE>
  79. <INPUT TYPE=SUBMIT NAME="Enter" VALUE="Enter" >
  80. </FORM>
  81. <%else %>
  82. <% ' Using record set which is easy, but an Insert would
  83.    ' have better performance (see DDJFIND.ASP)
  84.    Set Conn = Server.CreateObject("ADODB.Connection")
  85.    Conn.Open "KingSight","guest",""
  86.    set RS=Server.CreateObject("ADODB.RecordSet")
  87.    Conn.BeginTrans ' start a unit of work
  88.    rs.Open "Sighting", Conn, adOpenStatic, adLockOptimistic
  89.    rs.AddNew ' new record
  90.    rs("Date")=CDate(Request("KDate"))
  91.    if Request("Before")="on" then
  92.      rs("Before")=-1
  93.    else
  94.      rs("Before")=0
  95.    end if
  96.    rs("Location")=Request("Loc")
  97.    rs("Name")=Request("Name")
  98.    rs("Comment")=Request("Comment")
  99.    rs("subtime")=now
  100.    rs.Update
  101.    Conn.CommitTrans
  102.    rs.Close
  103.    Conn.Close
  104. %>
  105. <H1> Thanks for your report </H1>
  106. <P>Thank you very much!
  107. <A HREF=ddjfind.asp>Click here to view recent sightings!</A>
  108. <% end if %>
  109. </BODY>
  110. </HTML>
  111.  
  112.  
  113. Listing Two
  114. <!--#include file="adovbs.inc" -->
  115. <HTML>
  116. <HEAD>
  117. <TITLE>Find the King</TITLE>
  118. </HEAD>
  119. <BODY>
  120. <H1>Recent King Sightings: </H1>
  121. <!-- Create a connection to the database -->
  122. <% Set Conn = Server.CreateObject("ADODB.Connection")
  123.    Conn.Open "KingSight","guest",""
  124.    ' Execute SQL select
  125.    SQL="Select * from Sighting order by date desc"
  126.    set RS = Conn.Execute(SQL)
  127. %>
  128. <P>
  129. <TABLE BORDER=1>
  130. <TR>
  131.   <!-- print headers -->
  132.   <!-- last field is hidden -->
  133.   <% For i = 0 to RS.Fields.Count - 2 %>
  134.      <TD><B><%= RS(i).Name %></B></TD>
  135.   <% Next %>
  136. </TR>
  137. <!-- print table (except for last field -->
  138. <% Do While Not RS.EOF %>
  139.   <TR>
  140.   <% For i = 0 to RS.Fields.Count - 2 %>
  141.        <TD VALIGN=TOP>
  142.     <% if RS(i).Name<>"Before" then %>
  143.        <%= RS(i) %>
  144.     <% else %>
  145.        <% if RS(i)=0 then %>
  146.          N
  147.        <% else %>
  148.          Y
  149.        <% end if %>
  150.     <% end if %>
  151.        </TD>
  152.   <% Next %>
  153.   </TR>
  154. <%
  155.   RS.MoveNext  <!-- go to next record -->
  156.   Loop
  157.   RS.Close
  158.   Conn.Close
  159. %>
  160. </TABLE>
  161. <P>
  162. Be sure to add your sightings by clicking
  163. <A HREF="ddjrpt.asp">here</A>.
  164. </BODY>
  165. </HTML>
  166.  
  167.  
  168.